{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Examples of plotly-scala with Almond"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[32mimport \u001b[39m\u001b[36m$ivy.$\u001b[39m\n",
       "\u001b[32mimport \u001b[39m\u001b[36mplotly._, plotly.element._, plotly.layout._, plotly.Almond._\n",
       "\n",
       "// if you want to have the plots available without an internet connection:\n",
       "// init(offline=true)\n",
       "\n",
       "// restrict the output height to avoid scrolling in output cells\n",
       "\u001b[39m"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import $ivy.`org.plotly-scala::plotly-almond:0.7.0`\n",
    "import plotly._, plotly.element._, plotly.layout._, plotly.Almond._\n",
    "\n",
    "// if you want to have the plots available without an internet connection:\n",
    "// init(offline=true)\n",
    "\n",
    "// restrict the output height to avoid scrolling in output cells\n",
    "repl.pprinter() = repl.pprinter().copy(defaultHeight = 3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Line Charts\n",
    "## Basic Line Chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "      <script type=\"text/javascript\">\n",
       "        require.config({\n",
       "  paths: {\n",
       "    d3: 'https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min',\n",
       "    plotly: 'https://cdn.plot.ly/plotly-1.41.3.min',\n",
       "    jquery: 'https://code.jquery.com/jquery-3.3.1.min'\n",
       "  },\n",
       "\n",
       "  shim: {\n",
       "    plotly: {\n",
       "      deps: ['d3', 'jquery'],\n",
       "      exports: 'plotly'\n",
       "    }\n",
       "  }\n",
       "});\n",
       "        \n",
       "\n",
       "        require(['plotly'], function(Plotly) {\n",
       "          window.Plotly = Plotly;\n",
       "        });\n",
       "      </script>\n",
       "    "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "data": [
        {
         "type": "scatter",
         "x": [
          1,
          2,
          3,
          4
         ],
         "y": [
          10,
          15,
          13,
          17
         ]
        },
        {
         "type": "scatter",
         "x": [
          1,
          2,
          3,
          4
         ],
         "y": [
          16,
          5,
          11,
          9
         ]
        }
       ],
       "layout": {}
      },
      "text/html": [
       "<div class=\"chart\" id=\"plot-1\"></div>\n",
       "<script>require(['plotly'], function(Plotly) {\n",
       "  (function () {\n",
       "  var data0 = {\"x\":[1.0,2.0,3.0,4.0],\"y\":[10.0,15.0,13.0,17.0],\"type\":\"scatter\"};\n",
       "  var data1 = {\"x\":[1.0,2.0,3.0,4.0],\"y\":[16.0,5.0,11.0,9.0],\"type\":\"scatter\"};\n",
       "\n",
       "  var data = [data0, data1];\n",
       "  var layout = {};\n",
       "\n",
       "  Plotly.plot('plot-1', data, layout);\n",
       "})();\n",
       "});\n",
       "      </script>\n",
       "           "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[36mtrace1\u001b[39m: \u001b[32mScatter\u001b[39m = \u001b[33mScatter\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[33mDoubles\u001b[39m(\u001b[33mList\u001b[39m(\u001b[32m1.0\u001b[39m, \u001b[32m2.0\u001b[39m, \u001b[32m3.0\u001b[39m, \u001b[32m4.0\u001b[39m))),\n",
       "...\n",
       "\u001b[36mtrace2\u001b[39m: \u001b[32mScatter\u001b[39m = \u001b[33mScatter\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[33mDoubles\u001b[39m(\u001b[33mList\u001b[39m(\u001b[32m1.0\u001b[39m, \u001b[32m2.0\u001b[39m, \u001b[32m3.0\u001b[39m, \u001b[32m4.0\u001b[39m))),\n",
       "...\n",
       "\u001b[36mdata\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mScatter\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mScatter\u001b[39m(\n",
       "...\n",
       "\u001b[36mres2_3\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"plot-1\"\u001b[39m"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val trace1 = Scatter(\n",
    "  Seq(1, 2, 3, 4),\n",
    "  Seq(10, 15, 13, 17)\n",
    ")\n",
    "\n",
    "val trace2 = Scatter(\n",
    "  Seq(1, 2, 3, 4),\n",
    "  Seq(16, 5, 11, 9)\n",
    ")\n",
    "\n",
    "val data = Seq(trace1, trace2)\n",
    "\n",
    "plot(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Line and Scatter Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "data": [
        {
         "mode": "markers",
         "type": "scatter",
         "x": [
          1,
          2,
          3,
          4
         ],
         "y": [
          10,
          15,
          13,
          17
         ]
        },
        {
         "mode": "lines",
         "type": "scatter",
         "x": [
          2,
          3,
          4,
          5
         ],
         "y": [
          16,
          5,
          11,
          9
         ]
        },
        {
         "mode": "lines+markers",
         "type": "scatter",
         "x": [
          1,
          2,
          3,
          4
         ],
         "y": [
          12,
          9,
          15,
          12
         ]
        }
       ],
       "layout": {
        "title": "Line and Scatter Plot"
       }
      },
      "text/html": [
       "<div class=\"chart\" id=\"plot-2\"></div>\n",
       "<script>require(['plotly'], function(Plotly) {\n",
       "  (function () {\n",
       "  var data0 = {\"x\":[1.0,2.0,3.0,4.0],\"y\":[10.0,15.0,13.0,17.0],\"mode\":\"markers\",\"type\":\"scatter\"};\n",
       "  var data1 = {\"x\":[2.0,3.0,4.0,5.0],\"y\":[16.0,5.0,11.0,9.0],\"mode\":\"lines\",\"type\":\"scatter\"};\n",
       "  var data2 = {\"x\":[1.0,2.0,3.0,4.0],\"y\":[12.0,9.0,15.0,12.0],\"mode\":\"lines+markers\",\"type\":\"scatter\"};\n",
       "\n",
       "  var data = [data0, data1, data2];\n",
       "  var layout = {\"title\":\"Line and Scatter Plot\"};\n",
       "\n",
       "  Plotly.plot('plot-2', data, layout);\n",
       "})();\n",
       "});\n",
       "      </script>\n",
       "           "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[36mtrace1\u001b[39m: \u001b[32mScatter\u001b[39m = \u001b[33mScatter\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[33mDoubles\u001b[39m(\u001b[33mList\u001b[39m(\u001b[32m1.0\u001b[39m, \u001b[32m2.0\u001b[39m, \u001b[32m3.0\u001b[39m, \u001b[32m4.0\u001b[39m))),\n",
       "...\n",
       "\u001b[36mtrace2\u001b[39m: \u001b[32mScatter\u001b[39m = \u001b[33mScatter\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[33mDoubles\u001b[39m(\u001b[33mList\u001b[39m(\u001b[32m2.0\u001b[39m, \u001b[32m3.0\u001b[39m, \u001b[32m4.0\u001b[39m, \u001b[32m5.0\u001b[39m))),\n",
       "...\n",
       "\u001b[36mtrace3\u001b[39m: \u001b[32mScatter\u001b[39m = \u001b[33mScatter\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[33mDoubles\u001b[39m(\u001b[33mList\u001b[39m(\u001b[32m1.0\u001b[39m, \u001b[32m2.0\u001b[39m, \u001b[32m3.0\u001b[39m, \u001b[32m4.0\u001b[39m))),\n",
       "...\n",
       "\u001b[36mdata\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mScatter\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mScatter\u001b[39m(\n",
       "...\n",
       "\u001b[36mlayout\u001b[39m: \u001b[32mLayout\u001b[39m = \u001b[33mLayout\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[32m\"Line and Scatter Plot\"\u001b[39m),\n",
       "...\n",
       "\u001b[36mres3_5\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"plot-2\"\u001b[39m"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val trace1 = Scatter(\n",
    "  Seq(1, 2, 3, 4),\n",
    "  Seq(10, 15, 13, 17),\n",
    "  mode = ScatterMode(ScatterMode.Markers)\n",
    ")\n",
    "\n",
    "val trace2 = Scatter(\n",
    "  Seq(2, 3, 4, 5),\n",
    "  Seq(16, 5, 11, 9),\n",
    "  mode = ScatterMode(ScatterMode.Lines)\n",
    ")\n",
    "\n",
    "val trace3 = Scatter(\n",
    "  Seq(1, 2, 3, 4),\n",
    "  Seq(12, 9, 15, 12),\n",
    "  mode = ScatterMode(ScatterMode.Lines, ScatterMode.Markers)\n",
    ")\n",
    "\n",
    "val data = Seq(trace1, trace2, trace3)\n",
    "\n",
    "val layout = Layout(\n",
    "  title = \"Line and Scatter Plot\"\n",
    ")\n",
    "\n",
    "plot(data, layout)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Scatter Plots\n",
    "## Categorical Dot Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "data": [
        {
         "marker": {
          "color": "rgba(156, 165, 196, 0.95)",
          "line": {
           "color": "rgba(156, 165, 196, 1.0)",
           "width": 1
          },
          "size": 16,
          "symbol": "circle"
         },
         "mode": "markers",
         "name": "Percent of estimated voting age population",
         "type": "scatter",
         "x": [
          40,
          45.7,
          52,
          53.6,
          54.1,
          54.2,
          54.5,
          54.7,
          55.1,
          56.6
         ],
         "y": [
          "Switzerland (2011)",
          "Chile (2013)",
          "Japan (2014)",
          "United States (2012)",
          "Slovenia (2014)",
          "Canada (2011)",
          "Poland (2010)",
          "Estonia (2015)",
          "Luxembourg (2013)",
          "Portugal (2011)"
         ]
        },
        {
         "marker": {
          "color": "rgba(204, 204, 204, 0.95)",
          "line": {
           "color": "rgba(217, 217, 217, 1.0)",
           "width": 1
          },
          "size": 16,
          "symbol": "circle"
         },
         "mode": "markers",
         "name": "Percent of estimated registered voters",
         "type": "scatter",
         "x": [
          49.1,
          42,
          52.7,
          84.3,
          51.7,
          61.1,
          55.3,
          64.2,
          91.1,
          58.9
         ],
         "y": [
          "Switzerland (2011)",
          "Chile (2013)",
          "Japan (2014)",
          "United States (2012)",
          "Slovenia (2014)",
          "Canada (2011)",
          "Poland (2010)",
          "Estonia (2015)",
          "Luxembourg (2013)",
          "Portugal (2011)"
         ]
        }
       ],
       "layout": {
        "height": 400,
        "hovermode": "closest",
        "legend": {
         "font": {
          "size": 10
         },
         "xanchor": "right",
         "yanchor": "middle"
        },
        "margin": {
         "b": 50,
         "l": 140,
         "r": 40,
         "t": 80
        },
        "paper_bgcolor": "rgb(254, 247, 234)",
        "plot_bgcolor": "rgb(254, 247, 234)",
        "title": "Votes cast for ten lowest voting age population in OECD countries",
        "width": 600,
        "xaxis": {
         "autotick": false,
         "dtick": 10,
         "linecolor": "rgb(102, 102, 102)",
         "showgrid": false,
         "showline": true,
         "tickcolor": "rgb(102, 102, 102)",
         "tickfont": {
          "color": "rgb(102, 102, 102)"
         },
         "ticks": "outside",
         "titlefont": {
          "color": "rgb(204, 204, 204)"
         }
        }
       }
      },
      "text/html": [
       "<div class=\"chart\" id=\"plot-3\"></div>\n",
       "<script>require(['plotly'], function(Plotly) {\n",
       "  (function () {\n",
       "  var data0 = {\"x\":[40.0,45.7,52.0,53.6,54.1,54.2,54.5,54.7,55.1,56.6],\"name\":\"Percent of estimated voting age population\",\"y\":[\"Switzerland (2011)\",\"Chile (2013)\",\"Japan (2014)\",\"United States (2012)\",\"Slovenia (2014)\",\"Canada (2011)\",\"Poland (2010)\",\"Estonia (2015)\",\"Luxembourg (2013)\",\"Portugal (2011)\"],\"marker\":{\"size\":16,\"line\":{\"color\":\"rgba(156, 165, 196, 1.0)\",\"width\":1.0},\"color\":\"rgba(156, 165, 196, 0.95)\",\"symbol\":\"circle\"},\"mode\":\"markers\",\"type\":\"scatter\"};\n",
       "  var data1 = {\"x\":[49.1,42.0,52.7,84.3,51.7,61.1,55.3,64.2,91.1,58.9],\"name\":\"Percent of estimated registered voters\",\"y\":[\"Switzerland (2011)\",\"Chile (2013)\",\"Japan (2014)\",\"United States (2012)\",\"Slovenia (2014)\",\"Canada (2011)\",\"Poland (2010)\",\"Estonia (2015)\",\"Luxembourg (2013)\",\"Portugal (2011)\"],\"marker\":{\"size\":16,\"line\":{\"color\":\"rgba(217, 217, 217, 1.0)\",\"width\":1.0},\"color\":\"rgba(204, 204, 204, 0.95)\",\"symbol\":\"circle\"},\"mode\":\"markers\",\"type\":\"scatter\"};\n",
       "\n",
       "  var data = [data0, data1];\n",
       "  var layout = {\"margin\":{\"t\":80,\"b\":50,\"l\":140,\"r\":40},\"paper_bgcolor\":\"rgb(254, 247, 234)\",\"height\":400,\"legend\":{\"yanchor\":\"middle\",\"font\":{\"size\":10},\"xanchor\":\"right\"},\"plot_bgcolor\":\"rgb(254, 247, 234)\",\"title\":\"Votes cast for ten lowest voting age population in OECD countries\",\"hovermode\":\"closest\",\"xaxis\":{\"autotick\":false,\"linecolor\":\"rgb(102, 102, 102)\",\"titlefont\":{\"color\":\"rgb(204, 204, 204)\"},\"showline\":true,\"dtick\":10.0,\"ticks\":\"outside\",\"tickcolor\":\"rgb(102, 102, 102)\",\"showgrid\":false,\"tickfont\":{\"color\":\"rgb(102, 102, 102)\"}},\"width\":600};\n",
       "\n",
       "  Plotly.plot('plot-3', data, layout);\n",
       "})();\n",
       "});\n",
       "      </script>\n",
       "           "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[36mcountry\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mString\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[32m\"Switzerland (2011)\"\u001b[39m,\n",
       "...\n",
       "\u001b[36mvotingPop\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mDouble\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[32m40.0\u001b[39m,\n",
       "...\n",
       "\u001b[36mregVoters\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mDouble\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[32m49.1\u001b[39m,\n",
       "...\n",
       "\u001b[36mtrace1\u001b[39m: \u001b[32mScatter\u001b[39m = \u001b[33mScatter\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\n",
       "...\n",
       "\u001b[36mtrace2\u001b[39m: \u001b[32mScatter\u001b[39m = \u001b[33mScatter\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\n",
       "...\n",
       "\u001b[36mdata\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mScatter\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mScatter\u001b[39m(\n",
       "...\n",
       "\u001b[36mlayout\u001b[39m: \u001b[32mLayout\u001b[39m = \u001b[33mLayout\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[32m\"Votes cast for ten lowest voting age population in OECD countries\"\u001b[39m),\n",
       "...\n",
       "\u001b[36mres4_7\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"plot-3\"\u001b[39m"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val country = Seq(\n",
    "  \"Switzerland (2011)\",\n",
    "  \"Chile (2013)\",\n",
    "  \"Japan (2014)\",\n",
    "  \"United States (2012)\",\n",
    "  \"Slovenia (2014)\",\n",
    "  \"Canada (2011)\",\n",
    "  \"Poland (2010)\",\n",
    "  \"Estonia (2015)\",\n",
    "  \"Luxembourg (2013)\",\n",
    "  \"Portugal (2011)\"\n",
    ")\n",
    "\n",
    "val votingPop = Seq(\n",
    "  40.0, 45.7, 52.0, 53.6, 54.1, 54.2, 54.5, 54.7, 55.1, 56.6\n",
    ")\n",
    "\n",
    "val regVoters = Seq(\n",
    "  49.1, 42.0, 52.7, 84.3, 51.7, 61.1, 55.3, 64.2, 91.1, 58.9\n",
    ")\n",
    "\n",
    "val trace1 = Scatter(\n",
    "  votingPop,\n",
    "  country,\n",
    "  mode = ScatterMode(ScatterMode.Markers),\n",
    "  name = \"Percent of estimated voting age population\",\n",
    "  marker = Marker(\n",
    "    color = Color.RGBA(156, 165, 196, 0.95),\n",
    "    line = Line(\n",
    "      color = Color.RGBA(156, 165, 196, 1.0),\n",
    "      width = 1.0\n",
    "    ),\n",
    "    symbol = Symbol.Circle(),\n",
    "    size = 16\n",
    "  )\n",
    ")\n",
    "\n",
    "val trace2 = Scatter(\n",
    "  regVoters,\n",
    "  country,\n",
    "  mode = ScatterMode(ScatterMode.Markers),\n",
    "  name = \"Percent of estimated registered voters\",\n",
    "  marker = Marker(\n",
    "    color = Color.RGBA(204, 204, 204, 0.95),\n",
    "    line = Line(\n",
    "      color = Color.RGBA(217, 217, 217, 1.0),\n",
    "      width = 1.0\n",
    "    ),\n",
    "    symbol = Symbol.Circle(),\n",
    "    size = 16\n",
    "  )\n",
    ")\n",
    "\n",
    "val data = Seq(trace1, trace2)\n",
    "\n",
    "val layout = Layout(\n",
    "  title = \"Votes cast for ten lowest voting age population in OECD countries\",\n",
    "  xaxis = Axis(\n",
    "    showgrid = false,\n",
    "    showline = true,\n",
    "    linecolor = Color.RGB(102, 102, 102),\n",
    "    titlefont = Font(\n",
    "      color = Color.RGB(204, 204, 204)\n",
    "    ),\n",
    "    tickfont = Font(\n",
    "      color = Color.RGB(102, 102, 102)\n",
    "    ),\n",
    "    autotick = false,\n",
    "    dtick = 10.0,\n",
    "    ticks = Ticks.Outside,\n",
    "    tickcolor = Color.RGB(102, 102, 102)\n",
    "  ),\n",
    "  margin = Margin(\n",
    "    l = 140,\n",
    "    r = 40,\n",
    "    b = 50,\n",
    "    t = 80\n",
    "  ),\n",
    "  legend = Legend(\n",
    "    font = Font(\n",
    "      size = 10\n",
    "    ),\n",
    "    yanchor = Anchor.Middle,\n",
    "    xanchor = Anchor.Right\n",
    "  ),\n",
    "  width = 600,\n",
    "  height = 400,\n",
    "  paper_bgcolor = Color.RGB(254, 247, 234),\n",
    "  plot_bgcolor = Color.RGB(254, 247, 234),\n",
    "  hovermode = HoverMode.Closest\n",
    ")\n",
    "\n",
    "plot(data, layout)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Bar Charts\n",
    "## Basic Bar Chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "data": [
        {
         "type": "bar",
         "x": [
          "giraffes",
          "orangutans",
          "monkeys"
         ],
         "y": [
          20,
          14,
          23
         ]
        }
       ],
       "layout": {}
      },
      "text/html": [
       "<div class=\"chart\" id=\"plot-4\"></div>\n",
       "<script>require(['plotly'], function(Plotly) {\n",
       "  (function () {\n",
       "  var data0 = {\"x\":[\"giraffes\",\"orangutans\",\"monkeys\"],\"y\":[20.0,14.0,23.0],\"type\":\"bar\"};\n",
       "\n",
       "  var data = [data0];\n",
       "  var layout = {};\n",
       "\n",
       "  Plotly.plot('plot-4', data, layout);\n",
       "})();\n",
       "});\n",
       "      </script>\n",
       "           "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[36mdata\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mBar\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mBar\u001b[39m(\n",
       "...\n",
       "\u001b[36mres5_1\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"plot-4\"\u001b[39m"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val data = Seq(\n",
    "  Bar(\n",
    "    Seq(\"giraffes\", \"orangutans\", \"monkeys\"),\n",
    "    Seq(20, 14, 23)\n",
    "  )\n",
    ")\n",
    "\n",
    "plot(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Grouped Bar Chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "data": [
        {
         "name": "SF Zoo",
         "type": "bar",
         "x": [
          "giraffes",
          "orangutans",
          "monkeys"
         ],
         "y": [
          20,
          14,
          23
         ]
        },
        {
         "name": "LA Zoo",
         "type": "bar",
         "x": [
          "giraffes",
          "orangutans",
          "monkeys"
         ],
         "y": [
          12,
          18,
          29
         ]
        }
       ],
       "layout": {
        "barmode": "group"
       }
      },
      "text/html": [
       "<div class=\"chart\" id=\"plot-5\"></div>\n",
       "<script>require(['plotly'], function(Plotly) {\n",
       "  (function () {\n",
       "  var data0 = {\"x\":[\"giraffes\",\"orangutans\",\"monkeys\"],\"name\":\"SF Zoo\",\"y\":[20.0,14.0,23.0],\"type\":\"bar\"};\n",
       "  var data1 = {\"x\":[\"giraffes\",\"orangutans\",\"monkeys\"],\"name\":\"LA Zoo\",\"y\":[12.0,18.0,29.0],\"type\":\"bar\"};\n",
       "\n",
       "  var data = [data0, data1];\n",
       "  var layout = {\"barmode\":\"group\"};\n",
       "\n",
       "  Plotly.plot('plot-5', data, layout);\n",
       "})();\n",
       "});\n",
       "      </script>\n",
       "           "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[36mtrace1\u001b[39m: \u001b[32mBar\u001b[39m = \u001b[33mBar\u001b[39m(\n",
       "  \u001b[33mStrings\u001b[39m(\u001b[33mList\u001b[39m(\u001b[32m\"giraffes\"\u001b[39m, \u001b[32m\"orangutans\"\u001b[39m, \u001b[32m\"monkeys\"\u001b[39m)),\n",
       "...\n",
       "\u001b[36mtrace2\u001b[39m: \u001b[32mBar\u001b[39m = \u001b[33mBar\u001b[39m(\n",
       "  \u001b[33mStrings\u001b[39m(\u001b[33mList\u001b[39m(\u001b[32m\"giraffes\"\u001b[39m, \u001b[32m\"orangutans\"\u001b[39m, \u001b[32m\"monkeys\"\u001b[39m)),\n",
       "...\n",
       "\u001b[36mdata\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mBar\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mBar\u001b[39m(\n",
       "...\n",
       "\u001b[36mlayout\u001b[39m: \u001b[32mLayout\u001b[39m = \u001b[33mLayout\u001b[39m(\n",
       "  \u001b[32mNone\u001b[39m,\n",
       "...\n",
       "\u001b[36mres6_4\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"plot-5\"\u001b[39m"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val trace1 = Bar(\n",
    "  Seq(\"giraffes\", \"orangutans\", \"monkeys\"),\n",
    "  Seq(20, 14, 23),\n",
    "  name = \"SF Zoo\"\n",
    ")\n",
    "\n",
    "val trace2 = Bar(\n",
    "  Seq(\"giraffes\", \"orangutans\", \"monkeys\"),\n",
    "  Seq(12, 18, 29),\n",
    "  name = \"LA Zoo\"\n",
    ")\n",
    "\n",
    "val data = Seq(trace1, trace2)\n",
    "\n",
    "val layout = Layout(\n",
    "  barmode = BarMode.Group\n",
    ")\n",
    "\n",
    "plot(data, layout)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Bar Chart with Direct Labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "data": [
        {
         "marker": {
          "color": "rgb(158, 202, 225)",
          "line": {
           "color": "rgb(8, 48, 107)",
           "width": 1.5
          },
          "opacity": 0.6
         },
         "text": [
          "27% market share",
          "24% market share",
          "19% market share"
         ],
         "type": "bar",
         "x": [
          "Product A",
          "Product B",
          "Product C"
         ],
         "y": [
          20,
          14,
          23
         ]
        }
       ],
       "layout": {
        "annotations": [
         {
          "showarrow": false,
          "text": "20",
          "x": "Product A",
          "xanchor": "center",
          "y": 20,
          "yanchor": "bottom"
         },
         {
          "showarrow": false,
          "text": "14",
          "x": "Product B",
          "xanchor": "center",
          "y": 14,
          "yanchor": "bottom"
         },
         {
          "showarrow": false,
          "text": "23",
          "x": "Product C",
          "xanchor": "center",
          "y": 23,
          "yanchor": "bottom"
         }
        ],
        "title": "January 2013 Sales Report"
       }
      },
      "text/html": [
       "<div class=\"chart\" id=\"plot-6\"></div>\n",
       "<script>require(['plotly'], function(Plotly) {\n",
       "  (function () {\n",
       "  var data0 = {\"x\":[\"Product A\",\"Product B\",\"Product C\"],\"y\":[20.0,14.0,23.0],\"marker\":{\"line\":{\"color\":\"rgb(8, 48, 107)\",\"width\":1.5},\"color\":\"rgb(158, 202, 225)\",\"opacity\":0.6},\"text\":[\"27% market share\",\"24% market share\",\"19% market share\"],\"type\":\"bar\"};\n",
       "\n",
       "  var data = [data0];\n",
       "  var layout = {\"annotations\":[{\"x\":\"Product A\",\"y\":20.0,\"yanchor\":\"bottom\",\"text\":\"20\",\"showarrow\":false,\"xanchor\":\"center\"},{\"x\":\"Product B\",\"y\":14.0,\"yanchor\":\"bottom\",\"text\":\"14\",\"showarrow\":false,\"xanchor\":\"center\"},{\"x\":\"Product C\",\"y\":23.0,\"yanchor\":\"bottom\",\"text\":\"23\",\"showarrow\":false,\"xanchor\":\"center\"}],\"title\":\"January 2013 Sales Report\"};\n",
       "\n",
       "  Plotly.plot('plot-6', data, layout);\n",
       "})();\n",
       "});\n",
       "      </script>\n",
       "           "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[36mxValue\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mString\u001b[39m] = \u001b[33mList\u001b[39m(\u001b[32m\"Product A\"\u001b[39m, \u001b[32m\"Product B\"\u001b[39m, \u001b[32m\"Product C\"\u001b[39m)\n",
       "\u001b[36myValue\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mInt\u001b[39m] = \u001b[33mList\u001b[39m(\u001b[32m20\u001b[39m, \u001b[32m14\u001b[39m, \u001b[32m23\u001b[39m)\n",
       "\u001b[36mtrace1\u001b[39m: \u001b[32mBar\u001b[39m = \u001b[33mBar\u001b[39m(\n",
       "  \u001b[33mStrings\u001b[39m(\u001b[33mList\u001b[39m(\u001b[32m\"Product A\"\u001b[39m, \u001b[32m\"Product B\"\u001b[39m, \u001b[32m\"Product C\"\u001b[39m)),\n",
       "...\n",
       "\u001b[36mdata\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mBar\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mBar\u001b[39m(\n",
       "...\n",
       "\u001b[36mannotations\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mAnnotation\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mAnnotation\u001b[39m(\n",
       "...\n",
       "\u001b[36mlayout\u001b[39m: \u001b[32mLayout\u001b[39m = \u001b[33mLayout\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[32m\"January 2013 Sales Report\"\u001b[39m),\n",
       "...\n",
       "\u001b[36mres7_6\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"plot-6\"\u001b[39m"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val xValue = Seq(\"Product A\", \"Product B\", \"Product C\")\n",
    "\n",
    "val yValue = Seq(20, 14, 23)\n",
    "\n",
    "val trace1 = Bar(\n",
    "  xValue,\n",
    "  yValue,\n",
    "  text = Seq(\"27% market share\", \"24% market share\", \"19% market share\"),\n",
    "  marker = Marker(\n",
    "    color = Color.RGB(158, 202, 225),\n",
    "    opacity = 0.6,\n",
    "    line = Line(\n",
    "      color = Color.RGB(8, 48, 107),\n",
    "      width = 1.5\n",
    "    )\n",
    "  )\n",
    ")\n",
    "\n",
    "val data = Seq(trace1)\n",
    "\n",
    "val annotations = xValue.zip(yValue).map {\n",
    "  case (x, y) =>\n",
    "    Annotation(\n",
    "      x = x,\n",
    "      y = y,\n",
    "      text = y.toString,\n",
    "      xanchor = Anchor.Center,\n",
    "      yanchor = Anchor.Bottom,\n",
    "      showarrow = false\n",
    "    )\n",
    "}\n",
    "\n",
    "val layout = Layout(\n",
    "  title = \"January 2013 Sales Report\",\n",
    "  annotations = annotations\n",
    ")\n",
    "\n",
    "plot(data, layout)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Customizing Individual Bar Colors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "data": [
        {
         "marker": {
          "color": [
           "rgba(204, 204, 204, 1.0)",
           "rgba(222, 45, 38, 0.8)",
           "rgba(204, 204, 204, 1.0)",
           "rgba(204, 204, 204, 1.0)",
           "rgba(204, 204, 204, 1.0)"
          ]
         },
         "type": "bar",
         "x": [
          "Feature A",
          "Feature B",
          "Feature C",
          "Feature D",
          "Feature E"
         ],
         "y": [
          20,
          14,
          23,
          25,
          22
         ]
        }
       ],
       "layout": {
        "title": "Least Used Feature"
       }
      },
      "text/html": [
       "<div class=\"chart\" id=\"plot-7\"></div>\n",
       "<script>require(['plotly'], function(Plotly) {\n",
       "  (function () {\n",
       "  var data0 = {\"x\":[\"Feature A\",\"Feature B\",\"Feature C\",\"Feature D\",\"Feature E\"],\"y\":[20.0,14.0,23.0,25.0,22.0],\"marker\":{\"color\":[\"rgba(204, 204, 204, 1.0)\",\"rgba(222, 45, 38, 0.8)\",\"rgba(204, 204, 204, 1.0)\",\"rgba(204, 204, 204, 1.0)\",\"rgba(204, 204, 204, 1.0)\"]},\"type\":\"bar\"};\n",
       "\n",
       "  var data = [data0];\n",
       "  var layout = {\"title\":\"Least Used Feature\"};\n",
       "\n",
       "  Plotly.plot('plot-7', data, layout);\n",
       "})();\n",
       "});\n",
       "      </script>\n",
       "           "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[36mdefaultColor\u001b[39m: \u001b[32mColor\u001b[39m.\u001b[32mRGBA\u001b[39m = \u001b[33mRGBA\u001b[39m(\u001b[32m204\u001b[39m, \u001b[32m204\u001b[39m, \u001b[32m204\u001b[39m, \u001b[32m1.0\u001b[39m)\n",
       "\u001b[36mhighlightColor\u001b[39m: \u001b[32mColor\u001b[39m.\u001b[32mRGBA\u001b[39m = \u001b[33mRGBA\u001b[39m(\u001b[32m222\u001b[39m, \u001b[32m45\u001b[39m, \u001b[32m38\u001b[39m, \u001b[32m0.8\u001b[39m)\n",
       "\u001b[36mtrace1\u001b[39m: \u001b[32mBar\u001b[39m = \u001b[33mBar\u001b[39m(\n",
       "  \u001b[33mStrings\u001b[39m(\u001b[33mList\u001b[39m(\u001b[32m\"Feature A\"\u001b[39m, \u001b[32m\"Feature B\"\u001b[39m, \u001b[32m\"Feature C\"\u001b[39m, \u001b[32m\"Feature D\"\u001b[39m, \u001b[32m\"Feature E\"\u001b[39m))...\n",
       "\u001b[36mdata\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mBar\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mBar\u001b[39m(\n",
       "...\n",
       "\u001b[36mlayout\u001b[39m: \u001b[32mLayout\u001b[39m = \u001b[33mLayout\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[32m\"Least Used Feature\"\u001b[39m),\n",
       "...\n",
       "\u001b[36mres8_5\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"plot-7\"\u001b[39m"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val defaultColor = Color.RGBA(204,204,204,1)\n",
    "val highlightColor = Color.RGBA(222,45,38,0.8)\n",
    "\n",
    "val trace1 = Bar(\n",
    "  Seq(\"Feature A\", \"Feature B\", \"Feature C\", \"Feature D\", \"Feature E\"),\n",
    "  Seq(20, 14, 23, 25, 22),\n",
    "  marker = Marker(\n",
    "    color = Seq(\n",
    "      defaultColor, highlightColor, defaultColor, defaultColor, defaultColor\n",
    "    )\n",
    "  )\n",
    ")\n",
    "\n",
    "val data = Seq(trace1)\n",
    "\n",
    "val layout = Layout(\n",
    "  title = \"Least Used Feature\"\n",
    ")\n",
    "\n",
    "plot(data, layout)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Waterfall Bar Chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "data": [
        {
         "marker": {
          "color": "rgba(1, 1, 1, 0.0)"
         },
         "type": "bar",
         "x": [
          "Product Revenue",
          "Services Revenue",
          "Total Revenue",
          "Fixed Costs",
          "Variable Costs",
          "Total Costs",
          "Total"
         ],
         "y": [
          0,
          430,
          0,
          570,
          370,
          370,
          0
         ]
        },
        {
         "marker": {
          "color": "rgba(55, 128, 191, 0.7)",
          "line": {
           "color": "rgba(55, 128, 191, 1.0)",
           "width": 2
          }
         },
         "type": "bar",
         "x": [
          "Product Revenue",
          "Services Revenue",
          "Total Revenue",
          "Fixed Costs",
          "Variable Costs",
          "Total Costs",
          "Total"
         ],
         "y": [
          430,
          260,
          690,
          0,
          0,
          0,
          0
         ]
        },
        {
         "marker": {
          "color": "rgba(219, 64, 82, 0.7)",
          "line": {
           "color": "rgba(219, 64, 82, 1.0)",
           "width": 2
          }
         },
         "type": "bar",
         "x": [
          "Product Revenue",
          "Services Revenue",
          "Total Revenue",
          "Fixed Costs",
          "Variable Costs",
          "Total Costs",
          "Total"
         ],
         "y": [
          0,
          0,
          0,
          120,
          200,
          320,
          0
         ]
        },
        {
         "marker": {
          "color": "rgba(50, 171, 96, 0.7)",
          "line": {
           "color": "rgba(50, 171, 96, 1.0)",
           "width": 2
          }
         },
         "type": "bar",
         "x": [
          "Product Revenue",
          "Services Revenue",
          "Total Revenue",
          "Fixed Costs",
          "Variable Costs",
          "Total Costs",
          "Total"
         ],
         "y": [
          0,
          0,
          0,
          0,
          0,
          0,
          370
         ]
        }
       ],
       "layout": {
        "annotations": [
         {
          "font": {
           "color": "rgba(245, 246, 249, 1.0)",
           "family": "Arial",
           "size": 14
          },
          "showarrow": false,
          "text": "$430K",
          "x": "Product Revenue",
          "y": 400
         },
         {
          "font": {
           "color": "rgba(245, 246, 249, 1.0)",
           "family": "Arial",
           "size": 14
          },
          "showarrow": false,
          "text": "$260K",
          "x": "Services Revenue",
          "y": 660
         },
         {
          "font": {
           "color": "rgba(245, 246, 249, 1.0)",
           "family": "Arial",
           "size": 14
          },
          "showarrow": false,
          "text": "$690K",
          "x": "Total Revenue",
          "y": 660
         },
         {
          "font": {
           "color": "rgba(245, 246, 249, 1.0)",
           "family": "Arial",
           "size": 14
          },
          "showarrow": false,
          "text": "$-120K",
          "x": "Fixed Costs",
          "y": 590
         },
         {
          "font": {
           "color": "rgba(245, 246, 249, 1.0)",
           "family": "Arial",
           "size": 14
          },
          "showarrow": false,
          "text": "$-200K",
          "x": "Variable Costs",
          "y": 400
         },
         {
          "font": {
           "color": "rgba(245, 246, 249, 1.0)",
           "family": "Arial",
           "size": 14
          },
          "showarrow": false,
          "text": "$-320K",
          "x": "Total Costs",
          "y": 400
         },
         {
          "font": {
           "color": "rgba(245, 246, 249, 1.0)",
           "family": "Arial",
           "size": 14
          },
          "showarrow": false,
          "text": "$370K",
          "x": "Total",
          "y": 340
         }
        ],
        "barmode": "stack",
        "height": 400,
        "paper_bgcolor": "rgba(245, 246, 249, 1.0)",
        "plot_bgcolor": "rgba(245, 246, 249, 1.0)",
        "showlegend": false,
        "title": "Annual Profit 2015",
        "width": 600
       }
      },
      "text/html": [
       "<div class=\"chart\" id=\"plot-8\"></div>\n",
       "<script>require(['plotly'], function(Plotly) {\n",
       "  (function () {\n",
       "  var data0 = {\"x\":[\"Product Revenue\",\"Services Revenue\",\"Total Revenue\",\"Fixed Costs\",\"Variable Costs\",\"Total Costs\",\"Total\"],\"y\":[0.0,430.0,0.0,570.0,370.0,370.0,0.0],\"marker\":{\"color\":\"rgba(1, 1, 1, 0.0)\"},\"type\":\"bar\"};\n",
       "  var data1 = {\"x\":[\"Product Revenue\",\"Services Revenue\",\"Total Revenue\",\"Fixed Costs\",\"Variable Costs\",\"Total Costs\",\"Total\"],\"y\":[430.0,260.0,690.0,0.0,0.0,0.0,0.0],\"marker\":{\"line\":{\"color\":\"rgba(55, 128, 191, 1.0)\",\"width\":2.0},\"color\":\"rgba(55, 128, 191, 0.7)\"},\"type\":\"bar\"};\n",
       "  var data2 = {\"x\":[\"Product Revenue\",\"Services Revenue\",\"Total Revenue\",\"Fixed Costs\",\"Variable Costs\",\"Total Costs\",\"Total\"],\"y\":[0.0,0.0,0.0,120.0,200.0,320.0,0.0],\"marker\":{\"line\":{\"color\":\"rgba(219, 64, 82, 1.0)\",\"width\":2.0},\"color\":\"rgba(219, 64, 82, 0.7)\"},\"type\":\"bar\"};\n",
       "  var data3 = {\"x\":[\"Product Revenue\",\"Services Revenue\",\"Total Revenue\",\"Fixed Costs\",\"Variable Costs\",\"Total Costs\",\"Total\"],\"y\":[0.0,0.0,0.0,0.0,0.0,0.0,370.0],\"marker\":{\"line\":{\"color\":\"rgba(50, 171, 96, 1.0)\",\"width\":2.0},\"color\":\"rgba(50, 171, 96, 0.7)\"},\"type\":\"bar\"};\n",
       "\n",
       "  var data = [data0, data1, data2, data3];\n",
       "  var layout = {\"paper_bgcolor\":\"rgba(245, 246, 249, 1.0)\",\"height\":400,\"annotations\":[{\"x\":\"Product Revenue\",\"y\":400.0,\"text\":\"$430K\",\"font\":{\"color\":\"rgba(245, 246, 249, 1.0)\",\"family\":\"Arial\",\"size\":14},\"showarrow\":false},{\"x\":\"Services Revenue\",\"y\":660.0,\"text\":\"$260K\",\"font\":{\"color\":\"rgba(245, 246, 249, 1.0)\",\"family\":\"Arial\",\"size\":14},\"showarrow\":false},{\"x\":\"Total Revenue\",\"y\":660.0,\"text\":\"$690K\",\"font\":{\"color\":\"rgba(245, 246, 249, 1.0)\",\"family\":\"Arial\",\"size\":14},\"showarrow\":false},{\"x\":\"Fixed Costs\",\"y\":590.0,\"text\":\"$-120K\",\"font\":{\"color\":\"rgba(245, 246, 249, 1.0)\",\"family\":\"Arial\",\"size\":14},\"showarrow\":false},{\"x\":\"Variable Costs\",\"y\":400.0,\"text\":\"$-200K\",\"font\":{\"color\":\"rgba(245, 246, 249, 1.0)\",\"family\":\"Arial\",\"size\":14},\"showarrow\":false},{\"x\":\"Total Costs\",\"y\":400.0,\"text\":\"$-320K\",\"font\":{\"color\":\"rgba(245, 246, 249, 1.0)\",\"family\":\"Arial\",\"size\":14},\"showarrow\":false},{\"x\":\"Total\",\"y\":340.0,\"text\":\"$370K\",\"font\":{\"color\":\"rgba(245, 246, 249, 1.0)\",\"family\":\"Arial\",\"size\":14},\"showarrow\":false}],\"barmode\":\"stack\",\"plot_bgcolor\":\"rgba(245, 246, 249, 1.0)\",\"title\":\"Annual Profit 2015\",\"width\":600,\"showlegend\":false};\n",
       "\n",
       "  Plotly.plot('plot-8', data, layout);\n",
       "})();\n",
       "});\n",
       "      </script>\n",
       "           "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[36mxData\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mString\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[32m\"Product Revenue\"\u001b[39m,\n",
       "...\n",
       "\u001b[36myData\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mInt\u001b[39m] = \u001b[33mList\u001b[39m(\u001b[32m400\u001b[39m, \u001b[32m660\u001b[39m, \u001b[32m660\u001b[39m, \u001b[32m590\u001b[39m, \u001b[32m400\u001b[39m, \u001b[32m400\u001b[39m, \u001b[32m340\u001b[39m)\n",
       "\u001b[36mtextList\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mString\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[32m\"$430K\"\u001b[39m,\n",
       "...\n",
       "\u001b[36mtrace1\u001b[39m: \u001b[32mBar\u001b[39m = \u001b[33mBar\u001b[39m(\n",
       "  \u001b[33mStrings\u001b[39m(\n",
       "...\n",
       "\u001b[36mtrace2\u001b[39m: \u001b[32mBar\u001b[39m = \u001b[33mBar\u001b[39m(\n",
       "  \u001b[33mStrings\u001b[39m(\n",
       "...\n",
       "\u001b[36mtrace3\u001b[39m: \u001b[32mBar\u001b[39m = \u001b[33mBar\u001b[39m(\n",
       "  \u001b[33mStrings\u001b[39m(\n",
       "...\n",
       "\u001b[36mtrace4\u001b[39m: \u001b[32mBar\u001b[39m = \u001b[33mBar\u001b[39m(\n",
       "  \u001b[33mStrings\u001b[39m(\n",
       "...\n",
       "\u001b[36mdata\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mBar\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mBar\u001b[39m(\n",
       "...\n",
       "\u001b[36mannotations\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mAnnotation\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mAnnotation\u001b[39m(\n",
       "...\n",
       "\u001b[36mlayout\u001b[39m: \u001b[32mLayout\u001b[39m = \u001b[33mLayout\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[32m\"Annual Profit 2015\"\u001b[39m),\n",
       "...\n",
       "\u001b[36mres9_10\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"plot-8\"\u001b[39m"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val xData = Seq(\n",
    "  \"Product Revenue\",\n",
    "  \"Services Revenue\",\n",
    "  \"Total Revenue\",\n",
    "  \"Fixed Costs\",\n",
    "  \"Variable Costs\",\n",
    "  \"Total Costs\",\n",
    "  \"Total\"\n",
    ")\n",
    "\n",
    "val yData = Seq(400, 660, 660, 590, 400, 400, 340)\n",
    "\n",
    "val textList = Seq(\"$430K\", \"$260K\", \"$690K\", \"$-120K\", \"$-200K\", \"$-320K\", \"$370K\")\n",
    "\n",
    "//Base\n",
    "\n",
    "val trace1 = Bar(\n",
    "  x = xData,\n",
    "  y = Seq(0, 430, 0, 570, 370, 370, 0),\n",
    "  marker = Marker(\n",
    "    color = Color.RGBA(1, 1, 1, 0.0)\n",
    "  )\n",
    ")\n",
    "\n",
    "//Revenue\n",
    "\n",
    "val trace2 = Bar(\n",
    "  xData,\n",
    "  Seq(430, 260, 690, 0, 0, 0, 0),\n",
    "  marker = Marker(\n",
    "    color = Color.RGBA(55, 128, 191, 0.7),\n",
    "    line = Line(\n",
    "      color = Color.RGBA(55, 128, 191, 1.0),\n",
    "      width = 2.0\n",
    "    )\n",
    "  )\n",
    ")\n",
    "\n",
    "//Cost\n",
    "\n",
    "val trace3 = Bar(\n",
    "  xData,\n",
    "  Seq(0, 0, 0, 120, 200, 320, 0),\n",
    "  marker = Marker(\n",
    "    color = Color.RGBA(219, 64, 82, 0.7),\n",
    "    line = Line(\n",
    "      color = Color.RGBA(219, 64, 82, 1.0),\n",
    "      width = 2.0\n",
    "    )\n",
    "  )\n",
    ")\n",
    "\n",
    "//Profit\n",
    "\n",
    "val trace4 = Bar(\n",
    "  xData,\n",
    "  Seq(0, 0, 0, 0, 0, 0, 370),\n",
    "  marker = Marker(\n",
    "    color = Color.RGBA(50,171, 96, 0.7),\n",
    "    line = Line(\n",
    "      color = Color.RGBA(50, 171, 96, 1.0),\n",
    "      width = 2.0\n",
    "    )\n",
    "  )\n",
    ")\n",
    "\n",
    "val data = Seq(trace1, trace2, trace3, trace4)\n",
    "\n",
    "val annotations = xData.zip(yData).zip(textList).map {\n",
    "  case ((x, y), text) =>\n",
    "    Annotation(\n",
    "      x = x,\n",
    "      y = y,\n",
    "      text = text,\n",
    "      font = Font(\n",
    "        family = \"Arial\",\n",
    "        size = 14,\n",
    "        color = Color.RGBA(245, 246, 249, 1)\n",
    "      ),\n",
    "      showarrow = false\n",
    "    )\n",
    "}\n",
    "\n",
    "val layout = Layout(\n",
    "  title = \"Annual Profit 2015\",\n",
    "  barmode = BarMode.Stack,\n",
    "  paper_bgcolor = Color.RGBA(245, 246, 249, 1),\n",
    "  plot_bgcolor = Color.RGBA(245, 246, 249, 1),\n",
    "  width = 600,\n",
    "  height = 400,\n",
    "  showlegend = false,\n",
    "  annotations = annotations\n",
    ")\n",
    "\n",
    "plot(data, layout)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Horizontal Bar Charts\n",
    "## Basic Horizontal Bar Chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "data": [
        {
         "orientation": "h",
         "type": "bar",
         "x": [
          20,
          14,
          23
         ],
         "y": [
          "giraffes",
          "orangutans",
          "monkeys"
         ]
        }
       ],
       "layout": {}
      },
      "text/html": [
       "<div class=\"chart\" id=\"plot-9\"></div>\n",
       "<script>require(['plotly'], function(Plotly) {\n",
       "  (function () {\n",
       "  var data0 = {\"x\":[20.0,14.0,23.0],\"y\":[\"giraffes\",\"orangutans\",\"monkeys\"],\"orientation\":\"h\",\"type\":\"bar\"};\n",
       "\n",
       "  var data = [data0];\n",
       "  var layout = {};\n",
       "\n",
       "  Plotly.plot('plot-9', data, layout);\n",
       "})();\n",
       "});\n",
       "      </script>\n",
       "           "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[36mdata\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mBar\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mBar\u001b[39m(\n",
       "...\n",
       "\u001b[36mres10_1\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"plot-9\"\u001b[39m"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val data = Seq(Bar(\n",
    "  Seq(20, 14, 23),\n",
    "  Seq(\"giraffes\", \"orangutans\", \"monkeys\"),\n",
    "  orientation = Orientation.Horizontal\n",
    "))\n",
    "\n",
    "plot(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Colored Bar Chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "data": [
        {
         "marker": {
          "color": "rgba(55, 128, 191, 0.6)",
          "width": 1
         },
         "name": "SF Zoo",
         "orientation": "h",
         "type": "bar",
         "x": [
          20,
          14,
          23
         ],
         "y": [
          "giraffes",
          "orangutans",
          "monkeys"
         ]
        },
        {
         "marker": {
          "color": "rgba(255, 153, 51, 0.6)",
          "width": 1
         },
         "name": "LA Zoo",
         "orientation": "h",
         "type": "bar",
         "x": [
          12,
          18,
          29
         ],
         "y": [
          "giraffes",
          "orangutans",
          "monkeys"
         ]
        }
       ],
       "layout": {
        "barmode": "stack",
        "title": "Colored Bar Chart"
       }
      },
      "text/html": [
       "<div class=\"chart\" id=\"plot-10\"></div>\n",
       "<script>require(['plotly'], function(Plotly) {\n",
       "  (function () {\n",
       "  var data0 = {\"x\":[20.0,14.0,23.0],\"name\":\"SF Zoo\",\"y\":[\"giraffes\",\"orangutans\",\"monkeys\"],\"marker\":{\"color\":\"rgba(55, 128, 191, 0.6)\",\"width\":1},\"orientation\":\"h\",\"type\":\"bar\"};\n",
       "  var data1 = {\"x\":[12.0,18.0,29.0],\"name\":\"LA Zoo\",\"y\":[\"giraffes\",\"orangutans\",\"monkeys\"],\"marker\":{\"color\":\"rgba(255, 153, 51, 0.6)\",\"width\":1},\"orientation\":\"h\",\"type\":\"bar\"};\n",
       "\n",
       "  var data = [data0, data1];\n",
       "  var layout = {\"barmode\":\"stack\",\"title\":\"Colored Bar Chart\"};\n",
       "\n",
       "  Plotly.plot('plot-10', data, layout);\n",
       "})();\n",
       "});\n",
       "      </script>\n",
       "           "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[36mtrace1\u001b[39m: \u001b[32mBar\u001b[39m = \u001b[33mBar\u001b[39m(\n",
       "  \u001b[33mDoubles\u001b[39m(\u001b[33mList\u001b[39m(\u001b[32m20.0\u001b[39m, \u001b[32m14.0\u001b[39m, \u001b[32m23.0\u001b[39m)),\n",
       "...\n",
       "\u001b[36mtrace2\u001b[39m: \u001b[32mBar\u001b[39m = \u001b[33mBar\u001b[39m(\n",
       "  \u001b[33mDoubles\u001b[39m(\u001b[33mList\u001b[39m(\u001b[32m12.0\u001b[39m, \u001b[32m18.0\u001b[39m, \u001b[32m29.0\u001b[39m)),\n",
       "...\n",
       "\u001b[36mdata\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mBar\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mBar\u001b[39m(\n",
       "...\n",
       "\u001b[36mlayout\u001b[39m: \u001b[32mLayout\u001b[39m = \u001b[33mLayout\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[32m\"Colored Bar Chart\"\u001b[39m),\n",
       "...\n",
       "\u001b[36mres11_4\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"plot-10\"\u001b[39m"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val trace1 = Bar(\n",
    "  Seq(20, 14, 23),\n",
    "  Seq(\"giraffes\", \"orangutans\", \"monkeys\"),\n",
    "  name = \"SF Zoo\",\n",
    "  orientation = Orientation.Horizontal,\n",
    "  marker = Marker(\n",
    "    color = Color.RGBA(55, 128, 191, 0.6),\n",
    "    width = 1\n",
    "  )\n",
    ")\n",
    "\n",
    "val trace2 = Bar(\n",
    "  Seq(12, 18, 29),\n",
    "  Seq(\"giraffes\", \"orangutans\", \"monkeys\"),\n",
    "  name = \"LA Zoo\",\n",
    "  orientation = Orientation.Horizontal,\n",
    "  marker = Marker(\n",
    "    color = Color.RGBA(255, 153, 51, 0.6),\n",
    "    width = 1\n",
    "  )\n",
    ")\n",
    "\n",
    "val data = Seq(trace1, trace2)\n",
    "\n",
    "val layout = Layout(\n",
    "  title = \"Colored Bar Chart\",\n",
    "  barmode = BarMode.Stack\n",
    ")\n",
    "\n",
    "plot(data, layout)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Time Series\n",
    "## Time Series Chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "data": [
        {
         "type": "scatter",
         "x": [
          "2013-10-04 22:23:00",
          "2013-11-04 22:23:00",
          "2013-12-04 22:23:00"
         ],
         "y": [
          1,
          3,
          6
         ]
        }
       ],
       "layout": {}
      },
      "text/html": [
       "<div class=\"chart\" id=\"plot-11\"></div>\n",
       "<script>require(['plotly'], function(Plotly) {\n",
       "  (function () {\n",
       "  var data0 = {\"x\":[\"2013-10-04 22:23:00\",\"2013-11-04 22:23:00\",\"2013-12-04 22:23:00\"],\"y\":[1.0,3.0,6.0],\"type\":\"scatter\"};\n",
       "\n",
       "  var data = [data0];\n",
       "  var layout = {};\n",
       "\n",
       "  Plotly.plot('plot-11', data, layout);\n",
       "})();\n",
       "});\n",
       "      </script>\n",
       "           "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[36mdata\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mScatter\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mScatter\u001b[39m(\n",
       "...\n",
       "\u001b[36mres12_1\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"plot-11\"\u001b[39m"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val data = Seq(\n",
    "  Scatter(\n",
    "    Seq(\"2013-10-04 22:23:00\", \"2013-11-04 22:23:00\", \"2013-12-04 22:23:00\"),\n",
    "    Seq(1, 3, 6)\n",
    "  )\n",
    ")\n",
    "\n",
    "plot(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Bubble Charts\n",
    "## Hover on Text Bubble Chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "data": [
        {
         "marker": {
          "color": [
           "rgb(93, 164, 214)",
           "rgb(255, 144, 14)",
           "rgb(44, 160, 101)",
           "rgb(255, 65, 54)"
          ],
          "size": [
           40,
           60,
           80,
           100
          ]
         },
         "mode": "markers",
         "text": [
          "A\n  size = 40",
          "B\n  size = 60",
          "C\n  size = 80",
          "D\n  size = 100"
         ],
         "type": "scatter",
         "x": [
          1,
          2,
          3,
          4
         ],
         "y": [
          10,
          11,
          12,
          13
         ]
        }
       ],
       "layout": {
        "height": 400,
        "showlegend": false,
        "title": "Bubble Chart Hover Text",
        "width": 600
       }
      },
      "text/html": [
       "<div class=\"chart\" id=\"plot-12\"></div>\n",
       "<script>require(['plotly'], function(Plotly) {\n",
       "  (function () {\n",
       "  var data0 = {\"x\":[1.0,2.0,3.0,4.0],\"y\":[10.0,11.0,12.0,13.0],\"marker\":{\"size\":[40,60,80,100],\"color\":[\"rgb(93, 164, 214)\",\"rgb(255, 144, 14)\",\"rgb(44, 160, 101)\",\"rgb(255, 65, 54)\"]},\"text\":[\"A\\n  size = 40\",\"B\\n  size = 60\",\"C\\n  size = 80\",\"D\\n  size = 100\"],\"mode\":\"markers\",\"type\":\"scatter\"};\n",
       "\n",
       "  var data = [data0];\n",
       "  var layout = {\"height\":400,\"title\":\"Bubble Chart Hover Text\",\"width\":600,\"showlegend\":false};\n",
       "\n",
       "  Plotly.plot('plot-12', data, layout);\n",
       "})();\n",
       "});\n",
       "      </script>\n",
       "           "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[36mtrace1\u001b[39m: \u001b[32mScatter\u001b[39m = \u001b[33mScatter\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[33mDoubles\u001b[39m(\u001b[33mList\u001b[39m(\u001b[32m1.0\u001b[39m, \u001b[32m2.0\u001b[39m, \u001b[32m3.0\u001b[39m, \u001b[32m4.0\u001b[39m))),\n",
       "...\n",
       "\u001b[36mdata\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mScatter\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mScatter\u001b[39m(\n",
       "...\n",
       "\u001b[36mlayout\u001b[39m: \u001b[32mLayout\u001b[39m = \u001b[33mLayout\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[32m\"Bubble Chart Hover Text\"\u001b[39m),\n",
       "...\n",
       "\u001b[36mres13_3\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"plot-12\"\u001b[39m"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val trace1 = Scatter(\n",
    "  Seq(1, 2, 3, 4),\n",
    "  Seq(10, 11, 12, 13),\n",
    "  text = Seq(\"\"\"A\n",
    "  size = 40\"\"\", \"\"\"B\n",
    "  size = 60\"\"\", \"\"\"C\n",
    "  size = 80\"\"\", \"\"\"D\n",
    "  size = 100\"\"\"),\n",
    "  mode = ScatterMode(ScatterMode.Markers),\n",
    "  marker = Marker(\n",
    "    color = Seq(Color.RGB(93, 164, 214), Color.RGB(255, 144, 14), Color.RGB(44, 160, 101), Color.RGB(255, 65, 54)),\n",
    "    size = Seq(40, 60, 80, 100)\n",
    "  )\n",
    ")\n",
    "\n",
    "val data = Seq(trace1)\n",
    "\n",
    "val layout = Layout(\n",
    "  title = \"Bubble Chart Hover Text\",\n",
    "  showlegend = false,\n",
    "  height = 400,\n",
    "  width = 600\n",
    ")\n",
    "\n",
    "plot(data, layout)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Filled Area Plots\n",
    "## Basic Overlaid Area Chart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "data": [
        {
         "fill": "tozeroy",
         "type": "scatter",
         "x": [
          1,
          2,
          3,
          4
         ],
         "y": [
          0,
          2,
          3,
          5
         ]
        },
        {
         "fill": "tonexty",
         "type": "scatter",
         "x": [
          1,
          2,
          3,
          4
         ],
         "y": [
          3,
          5,
          1,
          7
         ]
        }
       ],
       "layout": {}
      },
      "text/html": [
       "<div class=\"chart\" id=\"plot-13\"></div>\n",
       "<script>require(['plotly'], function(Plotly) {\n",
       "  (function () {\n",
       "  var data0 = {\"x\":[1.0,2.0,3.0,4.0],\"y\":[0.0,2.0,3.0,5.0],\"fill\":\"tozeroy\",\"type\":\"scatter\"};\n",
       "  var data1 = {\"x\":[1.0,2.0,3.0,4.0],\"y\":[3.0,5.0,1.0,7.0],\"fill\":\"tonexty\",\"type\":\"scatter\"};\n",
       "\n",
       "  var data = [data0, data1];\n",
       "  var layout = {};\n",
       "\n",
       "  Plotly.plot('plot-13', data, layout);\n",
       "})();\n",
       "});\n",
       "      </script>\n",
       "           "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "\u001b[36mtrace1\u001b[39m: \u001b[32mScatter\u001b[39m = \u001b[33mScatter\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[33mDoubles\u001b[39m(\u001b[33mList\u001b[39m(\u001b[32m1.0\u001b[39m, \u001b[32m2.0\u001b[39m, \u001b[32m3.0\u001b[39m, \u001b[32m4.0\u001b[39m))),\n",
       "...\n",
       "\u001b[36mtrace2\u001b[39m: \u001b[32mScatter\u001b[39m = \u001b[33mScatter\u001b[39m(\n",
       "  \u001b[33mSome\u001b[39m(\u001b[33mDoubles\u001b[39m(\u001b[33mList\u001b[39m(\u001b[32m1.0\u001b[39m, \u001b[32m2.0\u001b[39m, \u001b[32m3.0\u001b[39m, \u001b[32m4.0\u001b[39m))),\n",
       "...\n",
       "\u001b[36mdata\u001b[39m: \u001b[32mSeq\u001b[39m[\u001b[32mScatter\u001b[39m] = \u001b[33mList\u001b[39m(\n",
       "  \u001b[33mScatter\u001b[39m(\n",
       "...\n",
       "\u001b[36mres14_3\u001b[39m: \u001b[32mString\u001b[39m = \u001b[32m\"plot-13\"\u001b[39m"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val trace1 = Scatter(\n",
    "  Seq(1, 2, 3, 4),\n",
    "  Seq(0, 2, 3, 5),\n",
    "  fill = Fill.ToZeroY\n",
    ")\n",
    "\n",
    "val trace2 = Scatter(\n",
    "  Seq(1, 2, 3, 4),\n",
    "  Seq(3, 5, 1, 7),\n",
    "  fill = Fill.ToNextY\n",
    ")\n",
    "\n",
    "val data = Seq(trace1, trace2)\n",
    "\n",
    "plot(data)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Scala",
   "language": "scala",
   "name": "scala"
  },
  "language_info": {
   "codemirror_mode": "text/x-scala",
   "file_extension": ".sc",
   "mimetype": "text/x-scala",
   "name": "scala",
   "nbconvert_exporter": "script",
   "version": "2.12.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}